package com.meltingslime.asciifight.server.network;

import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.TimerTask;

/**
 * @author Exit93
 * @version 1.0
 */
public class ClientsCleanerTask extends TimerTask{

    private ArrayList<Client> list;

    private Logger log = Logger.getLogger("asciifight.server.client");

    public ClientsCleanerTask(ArrayList<Client> list){
        this.list = list;
    }

    @Override
    public void run() {
        log.debug("Cleaning clients list");
        synchronized (ClientsCleanerTask.class){
            for (int i = 0; i < list.size(); i++){
                if (!list.get(i).isConnected())
                    list.remove(i);
            }
        }
    }
}
